package com.zr.sms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.sms.service.UpdateService;
import com.zr.sms.serviceimpl.UpdateServiceImpl;

import net.sf.json.JSONObject;

public class RukuServlet extends HttpServlet{
	UpdateService up=new UpdateServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
	    doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		 req.setCharacterEncoding("utf-8");
		  resp.setCharacterEncoding("utf-8");
		  String rukuinfo=req.getParameter("ruku");
		 JSONObject jobj=JSONObject.fromObject(rukuinfo);
		 String gid=jobj.getString("gid");
		 String[]gids=gid.split(",");//获取商品编号的字符串数组
		 String gnumber=jobj.getString("gnumbers");
		 String []gnumbers=gnumber.split(",");//获取商品进货数量的字符串数组
		 for (int i = 0; i < gnumbers.length; i++) {
			 up.updataGoods(Integer.parseInt(gids[i]), -Integer.parseInt(gnumbers[i]));
		}
		 String msg="商品已入库！！！";
		 PrintWriter out=resp.getWriter();
		 out.write(msg);
	
		 
		  
	}

}
